// 搜索功能
document.querySelector('.search-btn').addEventListener('click', function() {
	const studentName = document.getElementById('studentName').value.toLowerCase();
	const examNumber = document.getElementById('examNumber').value;
	const idNumber = document.getElementById('idNumber').value;
	const examSubject = document.getElementById('examSubject').value.toLowerCase();

	const rows = document.querySelectorAll('tbody tr');

	rows.forEach(row => {
		const name = row.children[1].textContent.toLowerCase();
		const exam = row.children[0].textContent;
		const id = row.children[3].textContent;
		const subject = row.children[4].textContent.toLowerCase();

		const matchName = !studentName || name.includes(studentName);
		const matchExam = !examNumber || exam.includes(examNumber);
		const matchId = !idNumber || id.includes(idNumber);
		const matchSubject = !examSubject || subject.includes(examSubject);

		row.style.display = (matchName && matchExam && matchId && matchSubject) ? '' : 'none';
	});
});

// 重置功能
document.querySelector('.reset-btn').addEventListener('click', function() {
	document.querySelectorAll('.search-form input').forEach(input => {
		input.value = '';
	});
	document.querySelectorAll('tbody tr').forEach(row => {
		row.style.display = '';
	});
});

// 操作图标功能
document.querySelectorAll('.action-icon').forEach(icon => {
	icon.addEventListener('click', function() {
		const row = this.closest('tr');
		const name = row.children[1].textContent;
		const action = this.textContent === '🗑️' ? '删除' : '查看';

		if (action === '删除') {
			if (confirm(`确定要删除考生 ${name} 的信息吗？`)) {
				row.remove();
			}
		} else {
			alert(`查看考生 ${name} 的详细信息`);
		}
	});
});

// 分页功能
document.querySelectorAll('.page-btn').forEach(btn => {
	btn.addEventListener('click', function() {
		if (this.textContent === '上一页' || this.textContent === '下一页') {
			return;
		}
		document.querySelectorAll('.page-btn').forEach(b => b.classList.remove('active'));
		this.classList.add('active');
	});
});

// 左侧菜单点击效果
document.querySelectorAll('.menu-item').forEach(item => {
	item.addEventListener('click', function() {
		document.querySelectorAll('.menu-item').forEach(i => {
			i.style.background = '';
		});
		this.style.background = 'rgba(255, 255, 255, 0.1)';
	});
});